package com.xgggh.redpack.utils;

import android.content.Context;

import android.graphics.drawable.Drawable;
import android.widget.EditText;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.databinding.BindingAdapter;

public class DataBindingUtils {

   /* public Drawable loadDrawable(Context context, int resourceId) {
        return  ContextCompat.getDrawable(context, resourceId);
    }*/

   @BindingAdapter({"android:drawableLeft"})
    public static void setDrawableLeft(TextView view, int resourceId) {
        Drawable drawable = ContextCompat.getDrawable(view.getContext(), resourceId);
        setIntrinsicBounds(drawable);
        Drawable[] drawables = view.getCompoundDrawables();
        view.setCompoundDrawables(drawable, drawables[1], drawables[2], drawables[3]);
    }

    private static void setIntrinsicBounds(Drawable drawable) {
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        }
    }

    //双向绑定edittext
    //https://www.jb51.net/article/126566.htm
    //https://www.jianshu.com/p/a05c9735f595





}
